package club.justwill.single.persistence.jpo;

import club.justwill.single.persistence.support.UserActivityBase;
import club.justwill.single.persistence.support.UserActivityPK;

import javax.persistence.*;
import java.io.Serializable;

/**
 * Created by luoyu on 15-12-24.
 */
@Entity
@Table(name = "user_activity")
@IdClass(UserActivityPK.class)
@NamedQueries({
        @NamedQuery(name = "UserActivity.getByUserId",
                query = "select u_act from UserActivity u_act where u_act.userId=:userId"),
        @NamedQuery(name = "UserActivity.getByUser8ActivityId",
                query = "select u_act from UserActivity u_act where u_act.userId =:userId and u_act.activityId =:activityId")
})
public class UserActivity extends UserActivityBase {

    //一个用户可以对应多个Userctivity 一对多 多方
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", referencedColumnName = "user_id",  insertable=false, updatable=false)
    private User user;

    //一个活动可以对应多个Userctivity 一对多 多方
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "activity_id", referencedColumnName = "activity_id",  insertable=false, updatable=false)
    private Activity activity;

    @Id
    @Column(name = "user_id")
    private Long userId;

    @Id
    @Column(name = "activity_id")
    private Long activityId;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Activity getActivity() {
        return activity;
    }

    public void setActivity(Activity activity) {
        this.activity = activity;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        if(userId == null) {
            this.userId = 0L;
        } else {
            this.userId = userId;
        }
    }

    public Long getActivityId() {
        return activityId;
    }

    public void setActivityId(Long activityId) {
        if(activityId == null) {
           this.activityId = 0L;
        } else {
            this.activityId = activityId;
        }
    }

}
